package spravaZamestnancov;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import strukturaZamestnanciNepritomnost.Nepritomnost;
import strukturaZamestnanciNepritomnost.Zamestnanci;
import strukturaZamestnanciNepritomnost.Zamestnanec;

/**
 *
 * @author Monika
 */
public class EditZamestnanec extends javax.swing.JFrame {

    /**
     * Creates new form EditZamestnanec
     */
    Zamestnanci zamestnanci;
    Zamestnanec z;
    ArrayList<Nepritomnost> nepritomnost;
    TreeMap<Integer, Integer> vztahy;
    final int id;
    DefaultListModel listModel;
    private DefaultTableModel dtm;
    private TreeMap<Integer, Integer> iToID; //mapuje poziciu v tabulke k id v databaze

    ;
    public EditZamestnanec(int id) {
        initComponents();

        //centralizovanie okna
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int X = (screen.width / 2) - (this.getWidth() / 2); // Center horizontally.
        int Y = (screen.height / 2) - (this.getHeight() / 2); // Center vertically.
        this.setLocation(X, Y);

        this.id = id;
        try {
            zamestnanci = new Zamestnanci();
        } catch (SQLException ex) {
            Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
        }
        z = zamestnanci.getZamestnanec(id);
        menoTextField.setText(z.getMeno());
        priezviskoTextField.setText(z.getPriezvisko());
        vahovanieText.setText(Double.toString(z.getVahovanie()));
        pocetDovolenkyText.setText(Double.toString(z.getPocetDniDovolenky()));
        typZamCB.setSelectedIndex(z.getTypZamestnanca());

        nepritomnost = zamestnanci.getNepritomnostZamestnanca(id);
        listModel = new DefaultListModel();
        nepritomnostList.setModel(listModel);

        for (int i = 0; i < nepritomnost.size(); i++) {
            listModel.addElement(nepritomnost.get(i).getDatum().toString());
        }
        for (int i = 1; i <= 31; i++) {
            denCB.addItem(i);
        }
        denCB.setSelectedItem(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        for (int i = 1; i <= 12; i++) {
            mesiacCB.addItem(i);
        }
        mesiacCB.setSelectedItem(Calendar.getInstance().get(Calendar.MONTH));
        for (int i = 2012; i <= Calendar.getInstance().get(Calendar.YEAR) + 1; i++) {
            rokCB.addItem(i);
        }
        rokCB.setSelectedItem(Calendar.getInstance().get(Calendar.YEAR));

        dtm = new DefaultTableModel();
        vztahyTable.setModel(dtm);
        String headers[] = new String[3];
        headers[0] = "ID";
        headers[1] = "Meno";
        headers[2] = "Vzťah";
        dtm.setColumnIdentifiers(headers);

        vztahy = z.getVztahy();
        for (int i : vztahy.keySet()) {
            Zamestnanec z2 = zamestnanci.getZamestnanec(i);
            dtm.addRow(new Object[]{i, z2.getMeno() + " " + z2.getPriezvisko(), vztahy.get(i)});
        }
        vztahyTable.setEnabled(false);

        TreeMap<Integer, Zamestnanec> zamestnanciZoznam = zamestnanci.getZamestnanciActive();
        iToID = new TreeMap<>();

        int j = 0;
        for (int i : zamestnanciZoznam.keySet()) {
            if (i != id) {
                zamestnanciCB.addItem(zamestnanciZoznam.get(i).getMeno() + " " + zamestnanciZoznam.get(i).getPriezvisko());
                iToID.put(j, i);
                j++;
            }
        }
        for (int i = -3; i <= 3; i++) {
            vztahyCB.addItem(i);
        }
        vztahyCB.setSelectedItem(0);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        saveButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        vahovanieText = new javax.swing.JTextField();
        menoTextField = new javax.swing.JTextField();
        priezviskoTextField = new javax.swing.JTextField();
        pocetDovolenkyText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        typZamCB = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        vztahPridatButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        vztahyTable = new javax.swing.JTable();
        zamestnanciCB = new javax.swing.JComboBox();
        vztahyCB = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        rokCB = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        dlzkaNepText = new javax.swing.JTextField();
        nepritPridatButton = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        denCB = new javax.swing.JComboBox();
        popisNepText = new javax.swing.JTextField();
        mesiacCB = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        nepritRemoveButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        nepritomnostList = new javax.swing.JList();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Upraviť zamestnanca");

        saveButton.setText("Uložiť");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setText("Počet dní dovolenky");

        jLabel4.setText("Váhovanie");

        vahovanieText.setText("0");

        pocetDovolenkyText.setText("0");

        jLabel1.setText("Meno");

        jLabel2.setText("Priezvisko");

        jLabel10.setText("Typ zamestnanca");

        typZamCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vrátnik", "Strážnik" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pocetDovolenkyText, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(vahovanieText, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(147, 147, 147)
                        .addComponent(priezviskoTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
                    .addComponent(menoTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(typZamCB, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(menoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(priezviskoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(vahovanieText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(pocetDovolenkyText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(typZamCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(52, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        vztahPridatButton.setText("Pridať");
        vztahPridatButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vztahPridatButtonActionPerformed(evt);
            }
        });

        vztahyTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2"
            }
        ));
        jScrollPane2.setViewportView(vztahyTable);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel9.setText("Vzťahy medzi zamestnancami");
        jLabel9.setToolTipText("");

        jLabel3.setText("* pre odstránenie vzťahu zvoľte 0");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(zamestnanciCB, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(vztahyCB, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(vztahPridatButton)
                    .addComponent(jLabel9))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(zamestnanciCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vztahyCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(vztahPridatButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel6.setText("Dĺžka");

        dlzkaNepText.setText("1");
        dlzkaNepText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dlzkaNepTextActionPerformed(evt);
            }
        });

        nepritPridatButton.setText("Pridať");
        nepritPridatButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nepritPridatButtonActionPerformed(evt);
            }
        });

        jLabel7.setText("Popis");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(nepritPridatButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel6))
                                .addGap(25, 25, 25)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(dlzkaNepText)
                                    .addComponent(popisNepText)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(denCB, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mesiacCB, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(rokCB, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(20, 20, 20))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(denCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mesiacCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rokCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dlzkaNepText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(popisNepText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(34, 34, 34)
                .addComponent(nepritPridatButton)
                .addContainerGap())
        );

        nepritRemoveButton.setText("Odstrániť");
        nepritRemoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nepritRemoveButtonActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(nepritomnostList);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nepritRemoveButton)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(nepritRemoveButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel8.setText("Neprítomnosť");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jLabel8)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(60, 60, 60)
                        .addComponent(saveButton))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        //ulozi zamestnanca, zatvori okno
        try {         
            double vahovanie = Double.parseDouble(vahovanieText.getText());
            double pocetDovolenky = Double.parseDouble(pocetDovolenkyText.getText());

            Zamestnanec novy = new Zamestnanec(menoTextField.getText().replaceAll(" ", ""),
                    priezviskoTextField.getText().replaceAll(" ", ""),
                    vahovanie, pocetDovolenky,
                    typZamCB.getSelectedIndex());
            try {
                // TODO add your handling code here:
                zamestnanci.editZamestnanec(id, novy);
            } catch (SQLException ex) {
                Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Nepodarilo sa uložiť zamestnanca!", "Chyba", JOptionPane.ERROR_MESSAGE);
                return;
            }
            setVisible(false);
            dispose();
        } catch (NumberFormatException ex) {
            Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Nesprávny číselný formát! Nepodarilo sa uložiť zamestnanca", "Chyba", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void nepritRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nepritRemoveButtonActionPerformed
        // odstrani nepritomnost
        if (nepritomnostList.getSelectedIndex() >= 0) {
            try {
                zamestnanci.removeNepritomnost(id, (String) nepritomnostList.getSelectedValue());
                System.out.println((String) nepritomnostList.getSelectedValue());
            } catch (SQLException | ParseException ex) {
                Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Nepodarilo sa odstrániť neprítomnosť!", "Chyba", JOptionPane.ERROR_MESSAGE);
            }
        }
        refreshNepritomnost();
    }//GEN-LAST:event_nepritRemoveButtonActionPerformed

    private void vztahPridatButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vztahPridatButtonActionPerformed
        // vlozi alebo zmeni vztah
        try {
            zamestnanci.editVztah(id, iToID.get(zamestnanciCB.getSelectedIndex()), (Integer) vztahyCB.getSelectedItem());
        } catch (SQLException ex) {
            Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Nepodarilo sa pridať vzťah!", "Chyba", JOptionPane.ERROR_MESSAGE);
        }
        refreshVztahy();
    }//GEN-LAST:event_vztahPridatButtonActionPerformed

    private void nepritPridatButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nepritPridatButtonActionPerformed
        //vlozi nepritomnost
        try {
            try {
                try {
                    // TODO add your handling code here:
                    String datum = Integer.toString((Integer) denCB.getSelectedItem()) + "." + Integer.toString((Integer) mesiacCB.getSelectedItem()) + "." + Integer.toString((Integer) rokCB.getSelectedItem());
                    zamestnanci.addNepritomnost(id, new Nepritomnost(datum, popisNepText.getText(), Double.parseDouble(dlzkaNepText.getText())));
                } catch (SQLException ex) {
                    Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, "Nepodarilo sa pridať neprítomnosť!", "Chyba", JOptionPane.ERROR_MESSAGE);
                }
            } catch (ParseException ex) {
                Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Nepodarilo sa pridať neprítomnosť!", "Chyba", JOptionPane.ERROR_MESSAGE);
            }
            refreshNepritomnost();
        } catch (NumberFormatException ex) {
            Logger.getLogger(EditZamestnanec.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Nesprávny číselný formát! Nepodarilo sa vložiť neprítomnosť.", "Chyba", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }//GEN-LAST:event_nepritPridatButtonActionPerformed

    private void dlzkaNepTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dlzkaNepTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dlzkaNepTextActionPerformed

    private void refreshNepritomnost() {
        /**
         * Obnoví tabuľku neprítomností.
         */
        nepritomnost = zamestnanci.getNepritomnostZamestnanca(id);
        listModel.clear();
        for (int i = 0; i < nepritomnost.size(); i++) {
            listModel.addElement(nepritomnost.get(i).getDatum().toString());
        }
    }

    private void refreshVztahy() {
        /**
         * Obnoví tabuľku vzťahov.
         */
        vztahy = z.getVztahy();
        dtm.setRowCount(0);
        for (int i : vztahy.keySet()) {
            Zamestnanec z2 = zamestnanci.getZamestnanec(i);
            dtm.addRow(new Object[]{i, z2.getMeno() + " " + z2.getPriezvisko(), vztahy.get(i)});
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditZamestnanec.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditZamestnanec.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditZamestnanec.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditZamestnanec.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox denCB;
    private javax.swing.JTextField dlzkaNepText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField menoTextField;
    private javax.swing.JComboBox mesiacCB;
    private javax.swing.JButton nepritPridatButton;
    private javax.swing.JButton nepritRemoveButton;
    private javax.swing.JList nepritomnostList;
    private javax.swing.JTextField pocetDovolenkyText;
    private javax.swing.JTextField popisNepText;
    private javax.swing.JTextField priezviskoTextField;
    private javax.swing.JComboBox rokCB;
    private javax.swing.JButton saveButton;
    private javax.swing.JComboBox typZamCB;
    private javax.swing.JTextField vahovanieText;
    private javax.swing.JButton vztahPridatButton;
    private javax.swing.JComboBox vztahyCB;
    private javax.swing.JTable vztahyTable;
    private javax.swing.JComboBox zamestnanciCB;
    // End of variables declaration//GEN-END:variables
}
